<template>
	<view class="content">
		<base-headers :isSearch="false"/>
		<view v-if="isVideo">
			<video-list v-for="item in newsData" :key="item.id" :isVideo="0" :videoData="item"/>
		</view>
		<base-detail v-else :data="newsData"/>
		<loading-more :isMore="isMore" @click.native="getMore"/>
		<top-button :top="top"/>
	</view>
</template>

<script>
	import {
		getNavigationContext
	} from '../../api/api.js'
import { debounce } from '../../utils/util'
	export default {
		data() {
			return {
				data: {
					pageSize: 10,
					pageNum: 1,
					isAsc: 'desc',
					orderByColumn: 'createTime',
					title: ''
				},
				newsData: [],
				isMore: 0,
				total: 0,
				isVideo: false,
				top:0
			}
		},
		onLoad(e) {
			this.data.title = e.title ? e.title : uni.getStorageSync('allNavigation')[0].itemTitle
			this.isVideo = this.data.title == '空中课堂' ? true : this.data.title == '微视频' ? true : false
			this.getData(this.data)
		},
		onPageScroll(e) {
			debounce(()=>{
				this.top = e.scrollTop
			})
		},
		onReachBottom() {
			this.getMore()
		},
		methods: {
			getData(data) {
				getNavigationContext(data).then(res => {
					this.total = res.total
					if (data.pageNum == 1) {
						this.newsData = res.data.records
					} else {
						this.newsData = this.newsData.concat(...res.data.records)
					}
					if(this.total <= this.data.pageNum * this.data.pageSize){
						this.isMore = 2
					}else{
						this.isMore = 0						
					}
				})
			},
			getMore() {
				this.isMore = 1
				if (this.data.pageNum * 10 < this.total) {
					this.data.pageNum++
					this.getData(this.data)
				} else {
					this.isMore = 2
				}
			}
		},
	}
</script>

<style lang="scss" scoped>

</style>
